package service

import (
	"multimedia/utils"
	"net/http"
	"strconv"

	"github.com/gin-gonic/gin"
)

// 查询个人设置
func (s *Srv) GetPersonalSettings(c *gin.Context) {
	userIdStr := c.Query("userId")
	userId, _ := strconv.ParseInt(userIdStr, 0, 64)
	set, err := s.mysql.GetPersonalSettings(userId)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"code": -1, "msg": err.Error(), "data": utils.EncryptDataByAes(nil)})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "", "data": utils.EncryptDataByAes(set)})
}

// 修改设置项
func (s *Srv) ModifySettings(c *gin.Context) {
	settingIdStr := c.Query("settingId")
	valueStr := c.Query("value")
	column := c.Query("column")
	settingId, _ := strconv.ParseInt(settingIdStr, 0, 64)
	value, _ := strconv.Atoi(valueStr)
	res, err := s.mysql.ModifySettings(settingId, column, value)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{"code": -1, "msg": err.Error(), "data": utils.EncryptDataByAes(false)})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 0, "msg": "", "data": utils.EncryptDataByAes(res)})
}
